import java.util.Random;

public class Test2 {
    //这个案例用于生成随机验证码
    public static void main(String[] args) {
        System.out.println("生成的验证码为"+CreateCode(8));
    }
    public static String CreateCode(int n){
        Random r = new Random();
        String Code = "";
        for (int i = 0; i < n; i++) {
            int type = r.nextInt(3);
            switch(type){
                case 0:                         //类型为0，生成0-9的随机数
                    Code += r.nextInt(10);
                    break;
                case 1:                         //类型为1，生成大写字母 ascll码为 65开头
                    char ch1 = (char) (r.nextInt(26) + 65);
                    Code +=ch1;
                    break;
                case 2:                         //类型为2,生成小写字母 ascll码为 97开头
                    char ch2 = (char) (r.nextInt(26) + 97);
                    Code += ch2;
                    break;
            }
        }
        return Code;
    }
}
